package com.changgou.oauth.config;

import com.changgou.oauth.util.JwtToken;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

/*****
 * @Author: 黑马训练营
 * @Description: com.changgou.oauth.config
 * Feign调用之前，会执行该拦截器方法
 ****/
@Configuration
public class FeignOauth2RequestInterceptor implements RequestInterceptor {

    /***
     * 调用feign之前会执行该方法
     * @param template
     */
    @Override
    public void apply(RequestTemplate template) {
        //调用之前，生成管理员令牌
        String token = JwtToken.adminJwt();

        // 并且封装到请求头中
        template.header("Authorization","bearer "+token);
    }
}
